<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class User_Model extends CI_Model {
	
	private $table= 'users';
	function __construct() {
		parent::__construct();
	}
	
	function login ($username, $password){
		$password = CommonUtils::encryptPassword($password);
    	$query = $this->db->get_where($this->table, array('username' => $username,'password'=>$password, 'is_active'=>1));
    	$result = $query->result();
    	return !empty($result);
	}
	
	function save($data){
		$this->db->insert($this->table, $data);
		return $this->db->insert_id();
	}
	
	function isClientAllowed($clientId, $userId) {
		$query = $this->db->get_where($this->table, array('id' => $userId,'client_id'=>$clientId));
    	$result = $query->result();
    	return !empty($result);
	}
}